<template>
	<view class="content">

		<view class="">
			<view class="u-flex u-row-center" style="margin-top: 100rpx;">
				<u-icon name="weixin-circle-fill" size="80" color="#00c923" />
			</view>
			<view class="u-border-top" style="padding: 30rpx;margin-top: 30rpx;">
				<view class="wm_weight_flod">登录后将获得以下权限</view>
				<view style="color: #8F8F94;margin-top: 30rpx;">
					获得您的公开信息(昵称、头像等)
				</view>
			</view>
			<view class="m-t-20">
				<u-button type="success" @tap="wxLogin" shape="circle" :custom-style="{width:'500rpx'}">授权登录</u-button>
			</view>
			<view class="m-t-20">
				<u-button type="success" @tap="goHome()" shape="circle" :custom-style="{width:'500rpx'}">继续浏览</u-button>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		login
	} from '@/api/user.js'
	import $store from "../../store";
	export default {
		data() {
			return {
				title: '微信授权登录',
				host: '' //配置为自己的额服务器即可
			}
		},
		onLoad() {

		},
		onReady() {
			$store.commit("SETBACKLOGIN", false)
		},
		methods: {
			goHome() {
				uni.switchTab({
					url: "/pages/index/index"
				})
			},
			wxLogin() {
				// 获取code 小程序专有，用户登录凭证。
				let that = this;
				uni.getUserProfile({
					desc: "获取用户基本资料",
					lang: 'zh_CN',
					success: (user) => {
						//获取成功基本资料后开启登录，因为基本资料首先要授权

						uni.login({
							provider: 'weixin',
							success: function(code_res) {
								if (code_res.errMsg == "login:ok") {
									let code = code_res.code;
									let spradUid = that.$store.getters.spreadUid

									let dd = user.userInfo;

									dd["spread_uid"] = parseInt(spradUid)
									console.log('that.$store.getter.spreadUid>>>>>>', JSON
										.stringify(dd))
									login(code, dd).then(res => {
										console.log("resssss>", JSON.stringify(res));
										that.$store.commit("LOGIN", res.data);
										console.log(111111);
										uni.switchTab({
											url: "/pages/index/index"
										});
									}).catch(err => {
										console.log('err', err)
									})

								}
							}
						});

					},
					fail: (res) => {
						uni.showModal({
							title: "用户拒绝授权",
							showCancel: false
						})
						     
					}
				});
			},
		}
	}
</script>

<style>
	.content {
		display: flex;
		flex-direction: column;
		align-items: center;
		justify-content: center;
	}

	.text-area {
		display: flex;
		justify-content: center;
	}

	.title {
		font-size: 36rpx;
		color: #8f8f94;
	}

	.bottom {
		margin-top: 400rpx;
	}
</style>
